import json

from flask import Flask, jsonify, request
from flask_cors import CORS  # 导入跨域支持模块

app = Flask(__name__)
CORS(app)  # 启用跨域访问支持，允许所有域名访问


# 或者更精确地配置CORS（可选）
# CORS(app, resources={r"/*": {"origins": "*"}})  # 允许所有域名访问所有路由
@app.route('/api/greet', methods=['GET', 'POST'])
def greet():
    with open('./data/EchartsMap.json','r',encoding='utf-8') as f:
        echarts_map = json.load(f)
    with open('./data/省份数据.json','r',encoding='utf-8') as f:
        province=json.load(f)

    response_data = {
        'echarts_map': echarts_map,
        'province': province,
        'state': 200
    }
    """示例接口，根据请求返回问候语"""
    if request.method == 'GET':
        return response_data

    elif request.method == 'POST':
        data = request.get_json()
        print(data)
        return response_data

@app.route('/baidu/wangyiyun')
def home():
    return "我的尝试！"


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)